package com.jiuyou.clientController.richEditor;

import com.jiuyou.clientController.base.ClientBaseController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.framework.web.service.MemberTokenService;
import com.ruoyi.richEditor.domain.RichEditorAttachment;
import com.ruoyi.richEditor.service.IRichEditorAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chengliang
 * @date 2021/10/29
 **/
@RestController
@RequestMapping("/client/richEditor")
public class RichEditorClientController extends ClientBaseController {
    @Autowired
    private MemberTokenService tokenService;
    @Autowired
    private IRichEditorAttachmentService richEditorService;
    @PutMapping
    public RichEditorAttachment insert(RichEditorAttachment attachment){
        Long memberId = tokenService.getLoginMemberId();
        attachment.setAnyId(memberId);
        richEditorService.insertRichEditorAttachment(attachment);
        return attachment;
    }
    @GetMapping("/{id}")
    public RichEditorAttachment get(@PathVariable Long id){
        return richEditorService.selectRichEditorAttachmentById(id);
    }
    @GetMapping("/byType/{type}")
    public List<RichEditorAttachment> getByType(@PathVariable String type){
        RichEditorAttachment attr = new RichEditorAttachment();
        attr.setAnyId(tokenService.getLoginMemberId());
        attr.setAttType(type);
        return richEditorService.selectRichEditorAttachmentList(attr);
    }
    @PutMapping("/edit")
    public int get(@RequestBody RichEditorAttachment attachment){
        return richEditorService.updateRichEditorAttachment(attachment);
    }
    @RequestMapping("/del/{id}")
    public Integer del(@PathVariable Long id){
        return richEditorService.deleteRichEditorAttachmentById(id);
    }
}
